#!/usr/bin/env python """ Example of a simple embedded engine in a pyside qt4 application. """ from PySide import QtGui, QtCore from ptk_lib.engine import pyside_engine, eng_misc class TestApp(QtGui.QApplication): def __init__(self): QtGui.QApplication.__init__(self, []) self.main = QtGui.QMainWindow() self.main.show() #close the engine when the app exits self.connect(self, QtCore.SIGNAL("lastWindowClosed()"), self, QtCore.SLOT("quit()")) #use the __main__ namespace (this file) as the top #level. import __main__ usr_dict = __main__.__dict__ #Alternatively this could be an empty dictionary in which you #can store objects you want to expose to the engine. usr_dict = {} usr_dict['a'] = 1 #expose objects to the engine. usr_dict['b'] = 'test string' #create the engine object # parent - the parent wxpython object used for events # engine label - The label display to the user on the console tab in # PTK # userdict - the local dictionary for the top level namespace self.eng = pyside_engine.pysideEngine( self, 'pysideTestApp',usr_dict, ) #connect to the engine disconnect signals self.connect(self, QtCore.SIGNAL( pyside_engine.SigDisconnect), self.on_engine_disconnect) #connect to a running PTK instance port = eng_misc.get_message_port() self.eng.connect( 'localhost', port) def quit(self): #disconnect the engine before quitting. self.eng.disconnect() QtGui.QApplication.quit() def on_engine_disconnect(self): print 'Engine disconnected' app = TestApp() app.exec_()